<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
require ("sql.php");
if ( !$_SESSION['user_id'] )
{ 
echo "Bạn chưa đăng nhập! <a href='login.php'>Nhấp vào đây để đăng nhập</a> "; 
}
else{
$user_id = ($_SESSION['user_id']);
$sql_query = @mysql_query("SELECT * FROM user WHERE tai_khoan='{$user_id}'");
$user = @mysql_fetch_array( $sql_query ); 
?>
 <?php if ($user['admin']=="3" && $user['admin']=="2") echo" <a> bạn không có quyền truy cập vào trang này</a>";
else { ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Thêm Học Sinh</title>
</head>

<body>
<a style="float:right" href="index.php">Quay lại trang chủ</a>
<?php require ("sql.php"); 
mysql_query("SET NAMES 'utf8'");
?>
  <?php
  if ( $_GET['act'] == "do" )
  {
$m_hs= $_POST[ "m_hs"];
$ten=$_POST["ten"];
$phai= $_POST["phai"];
$noi_sinh=$_POST["noi_sinh"];
$m_lop= $_POST["m_lop"];

$result= @mysql_query("INSERT INTO hs (m_hs,ten,phai,noi_sinh,m_lop) VALUES 
('{$m_hs}','{$ten}','{$phai}','{$noi_sinh}','{$m_lop}')");
if($result && $m_hs !='' && $ten != '' && $noi_sinh != '') 

	echo " Thêm thành công";

else

	echo "Kiểm tra lại thông tin";
}
else
{
print <<<EOF
<form action="themhs.php?act=do" method="post" name="form1" >
  <table width="260" border="1" align="center" cellpadding="1" cellspacing="5">
    <tr>
      <td style='align:center' colspan="2">Thêm Học Sinh Mới </td>
    </tr>
    <tr>
      <td>Mã Học Sinh </td>
      <td><label>
        <input name="m_hs" type="text"  value="" />
      </label></td>
    </tr>
    <tr>
      <td>Họ Tên</td>
      <td><label>
        <input name="ten" type="text"  value="" />
      </label></td>
    </tr>
    <tr>
      <td>Phái </td>
      <td><label>
       <select name="phai" id="phai">
    <option value="1">Nam</option>
    <option value="0">Nữ</option>
  </select>
      </label></td>
    </tr>
    
    <tr>
      <td>Nơi Sinh </td>
      <td><label>
        <input name="noi_sinh" type="text"  value="" />
      </label></td>
    </tr>
    <tr>
      <td>Lớp </td>
      <td><label>
       <select name="m_lop" id="m_lop">
    <option value="6a12">lớp 6a</option>
    <option value="6b12">lớp 6b</option>
	<option value="6c12">lớp 6c</option>
	<option value="7a12">lớp 7a</option>
	<option value="7b12">lớp 7b</option>
	<option value="7c12">lớp 7c</option>
	<option value="8a12">lớp 8a</option>
	<option value="8b12">lớp 8b</option>
	<option value="8c12">lớp 8c</option>
	<option value="9a12">lớp 9a</option>
	<option value="9b12">lớp 9b</option>
	<option value="9c12">lớp 9c</option>
	
  </select>
      </label></td>
    </tr>
    
    <tr>
      <td>&nbsp;</td>
      <td><label>
      <div align="center">
        <input type="submit" name="Submit" value="them" />
      </div>
      </label></td>
    </tr>
    
  </table>
</form>
EOF;
}
}
}
?>
</body>
</html>
